package com.pur.zsms.supplier.service.impl;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.annotation.Resource;

import net.sf.cglib.beans.BeanCopier;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.commons.beanutils.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.pur.zsms.common.exception.GenericException;
import com.pur.zsms.common.support.PageController;
import com.pur.zsms.common.support.PaginationSupport;
import com.pur.zsms.common.util.DeleteFileUtil;
import com.pur.zsms.common.util.PubFun;
import com.pur.zsms.common.vo.CommonType;
import com.pur.zsms.dao.SupplierShopDao;
import com.pur.zsms.matermanage.mater.dao.IMaterDao;
import com.pur.zsms.matermanage.mater.po.MaterLevelCblPo;
import com.pur.zsms.matermanage.mater.po.MaterLevelPo;
import com.pur.zsms.matermanage.mater.service.MaterComputeService;
import com.pur.zsms.matermanage.mater.vo.MaterVo;
import com.pur.zsms.matermanage.mater.vo.MaterVoForCostSupplier;
import com.pur.zsms.ordercustommanage.dao.ISelectFoodDao;
import com.pur.zsms.ordercustommanage.po.OrderSupplierMaterPo;
import com.pur.zsms.ordercustommanage.po.OrderSupplierMaterRealPo;
import com.pur.zsms.ordercustommanage.po.OrderSupplierPo;
import com.pur.zsms.ordercustommanage.vo.SelectFoodVo;
import com.pur.zsms.pmsnmanage.user.dao.IUserDao;
import com.pur.zsms.pmsnmanage.user.po.UserRolePo;
import com.pur.zsms.pmsnmanage.user.service.IUserService;
import com.pur.zsms.pmsnmanage.user.service.impl.UserServiceImpl;
import com.pur.zsms.po.SupplierShopPo;
import com.pur.zsms.shopmanage.dao.IShopDao;
import com.pur.zsms.shopmanage.po.ShopPo;
import com.pur.zsms.storemanage.po.StorePo;
import com.pur.zsms.supplier.dao.SupplierDao;
import com.pur.zsms.supplier.dao.SupplierOrderDao;
import com.pur.zsms.supplier.po.ShopSupplierTypePo;
import com.pur.zsms.supplier.po.SupplierDistributePo;
import com.pur.zsms.supplier.po.SupplierPo;
import com.pur.zsms.supplier.po.SupplierQualificationPo;
import com.pur.zsms.supplier.po.SupplierTypePo;
import com.pur.zsms.supplier.po.SupplierUserPo;
import com.pur.zsms.supplier.service.ISupplierService;
import com.pur.zsms.supplier.vo.ShopSupplierTypeVo;
import com.pur.zsms.supplier.vo.ShopSupplierVo;
import com.pur.zsms.supplier.vo.SupplierDistributeVo;
import com.pur.zsms.supplier.vo.SupplierOrderCustVo;
import com.pur.zsms.supplier.vo.SupplierQualificationVo;
import com.pur.zsms.supplier.vo.SupplierUserVo;
import com.pur.zsms.supplier.vo.SupplierVo;
import com.pur.zsms.systemsetting.datadictionary.po.Code;
import com.pur.zsms.systemsetting.datadictionary.vo.CodeVo;
import com.pur.zsms.vo.SupplierShopVo;

@Service("supplierService")
public class SupplierServiceImpl implements ISupplierService {
	String msg = "";

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	@Resource(name = "materComputerService")
	private MaterComputeService materComputerServiceImpl;

	@Resource(name = "userService")
	private IUserService userService;

	public IUserService getUserService() {
		return userService;
	}

	public void setUserService(IUserService userService) {
		this.userService = userService;
	}

	public MaterComputeService getMaterComputerServiceImpl() {
		return materComputerServiceImpl;
	}

	public void setMaterComputerServiceImpl(MaterComputeService materComputerServiceImpl) {
		this.materComputerServiceImpl = materComputerServiceImpl;
	}

	@Resource(name = "selectFoodDao")
	private ISelectFoodDao selectFoodDaoImpl;

	public ISelectFoodDao getSelectFoodDaoImpl() {
		return selectFoodDaoImpl;
	}

	public void setSelectFoodDaoImpl(ISelectFoodDao selectFoodDaoImpl) {
		this.selectFoodDaoImpl = selectFoodDaoImpl;
	}

	@Resource(name = "supplierOrderDao")
	private SupplierOrderDao supplierOrderDao;

	public SupplierOrderDao getSupplierOrderDao() {
		return supplierOrderDao;
	}

	public void setSupplierOrderDao(SupplierOrderDao supplierOrderDao) {
		this.supplierOrderDao = supplierOrderDao;
	}

	@Resource(name = "supplierDao")
	private SupplierDao supplierDao;

	@Resource(name = "supplierShopDao")
	private SupplierShopDao supplierShopDao;

	public SupplierDao getSupplierDao() {
		return supplierDao;
	}

	public void setSupplierDao(SupplierDao supplierDao) {
		this.supplierDao = supplierDao;
	}

	@Resource(name = "userDao")
	private IUserDao userDaoImpl;

	@Resource(name = "shopDao")
	private IShopDao shopDaoImpl;

	public IShopDao getShopDaoImpl() {
		return shopDaoImpl;
	}

	public void setShopDaoImpl(IShopDao shopDaoImpl) {
		this.shopDaoImpl = shopDaoImpl;
	}

	public IUserDao getUserDaoImpl() {
		return userDaoImpl;
	}

	public void setUserDaoImpl(IUserDao userDaoImpl) {
		this.userDaoImpl = userDaoImpl;
	}

	@Resource(name = "materDao")
	private IMaterDao materDaoImpl;

	public IMaterDao getMaterDaoImpl() {
		return materDaoImpl;
	}

	public void setMaterDaoImpl(IMaterDao foodDaoImpl) {
		this.materDaoImpl = foodDaoImpl;
	}

	@Override
	public PaginationSupport listSupplier(PageController pageController, SupplierVo supplierVo) throws GenericException {
		return supplierDao.listSupplier(pageController, supplierVo);
	}

	@Transactional(readOnly = true)
	public PaginationSupport listSupplierCost(PageController pageController, MaterVoForCostSupplier tMaterVo) throws GenericException {
		return supplierDao.listSupplierCost(pageController, tMaterVo);
	}

	public PaginationSupport listSupplier(PageController pageController, MaterVo tMaterVo) throws GenericException {
		return supplierDao.listSupplier(pageController, tMaterVo);

	}

	public PaginationSupport findCustForOrder(PageController pageController, SupplierOrderCustVo supplierOrderCustVo) throws GenericException {
		return supplierDao.findCustForOrder(pageController, supplierOrderCustVo);
	}

	public PaginationSupport findSupDistribute(PageController pageController, SupplierDistributeVo supplierDistributeVo) throws GenericException {
		return supplierDao.findSupDistribute(pageController, supplierDistributeVo);

	}

	public PaginationSupport findSupplierQualification(PageController pageController, SupplierQualificationVo supplierQualificationVo)
			throws GenericException {
		return supplierDao.findSupplierQualification(pageController, supplierQualificationVo);
	}

	@Override
	public PaginationSupport listSupCus(PageController pageController, ShopSupplierVo suppCusVo) throws GenericException {
		return supplierDao.listSupCus(pageController, suppCusVo);
	}

	@Override
	public boolean addSupplier(SupplierVo supplierVo) throws GenericException {
		boolean flag = true;
		// 校验相同名字
		List<SupplierPo> list = supplierDao.getSupPoByName(supplierVo.getCompanyName());
		if (list != null && list.size() > 0) {
			msg = "msg0004";
			return false;
		}
		BeanCopier copier = BeanCopier.create(SupplierVo.class, SupplierPo.class, false);
		SupplierPo supplierPo = new SupplierPo();
		supplierVo.setInsertTime(PubFun.getCurrentDate());
		copier.copy(supplierVo, supplierPo, null);
		supplierDao.addSupplier(supplierPo);
		long[] suptype = supplierVo.getSuptypes();
		if (suptype != null) {
			for (long materType : suptype) {
				SupplierTypePo supplierTypePo = new SupplierTypePo();
				supplierTypePo.setMaterType((int) materType);
				supplierTypePo.setSupId(supplierPo.getSupplierId());
				userDaoImpl.addSupplierTypePo(supplierTypePo);
			}
		}

		// 增加供货商和员工的关系表
		if (supplierVo.getUserFlag() == 3 && supplierVo.getUserId() != 0) {
			SupplierUserPo suPo = new SupplierUserPo();
			suPo.setUserId((int) supplierVo.getUserId());
			suPo.setSupId(supplierPo.getSupplierId());
			supplierDao.addSupplierUserPo(suPo);
		}

		return flag;
	}

	public boolean addSupplierDistribute(SupplierDistributeVo supplierDistributeVo) throws GenericException {
		boolean flag = true;
		String[] custIdArray = supplierDistributeVo.getCustIdAll().split(",");
		List<Object> disId = supplierDao.getMaxSupplierDistributeDisId(supplierDistributeVo.getDisDate(), supplierDistributeVo.getSupId());
		for (String custId : custIdArray) {
			SupplierDistributePo supplierDistributePo = new SupplierDistributePo();
			supplierDistributePo.setCustId(Long.valueOf(custId));
			supplierDistributePo.setDisDate(supplierDistributeVo.getDisDate());
			supplierDistributePo.setDisId(Long.valueOf(disId.get(0).toString()));
			supplierDistributePo.setOverFlag(0);
			supplierDistributePo.setSupId(supplierDistributeVo.getSupId());
			supplierDao.addSupplierDistribute(supplierDistributePo);
		}

		return flag;
	}

	@Override
	public void updateUser(SupplierPo supplierPo) throws GenericException {
		supplierDao.updateSupplier(supplierPo);
	}

	@Override
	public void deleteUser(int supplierId) throws GenericException {
		SupplierPo supplierPo = supplierDao.findSupplierById(supplierId);
		supplierDao.deleteSupplier(supplierPo);
	}

	public void deleteSupplierDistribute(long disId, int supId, String disDate) throws GenericException {
		supplierDao.deleteSupplierDistribute(disId, supId, disDate);
	}

	public String getAllSupPoJsonString(int space) throws GenericException {
		List<SupplierPo> tSupplierPoList = null;
		tSupplierPoList = supplierDao.getAllSupPoCust();

		StringBuffer ql = new StringBuffer();
		ql.append("[");
		if (space == 1) {
			ql.append("{\"supId\":\"0\",\"supName\":\"无\"},");
		} else if (space == 2) {
			ql.append("{\"supId\":\"0\",\"supName\":\"全部\"},");
		}
		String q2 = "";
		if (tSupplierPoList != null && tSupplierPoList.size() > 0) {
			for (SupplierPo supplierPo : tSupplierPoList) {
				ql.append("{\"supId\":\"" + supplierPo.getSupplierId() + "\",\"supName\":\"" + supplierPo.getCompanyName() + "\"},");
			}
			q2 = ql.substring(0, ql.length() - 1) + "]";
		}
		return q2;
	}

	public String getAllSup() throws GenericException {
		List<SupplierPo> supplierList = supplierDao.getAllSup();
		StringBuffer jsonUserTestValue = new StringBuffer("");

		if (supplierList != null && supplierList.size() > 0) {

			jsonUserTestValue.append("[");
			for (SupplierPo supplierPo : supplierList) {
				jsonUserTestValue.append("{\"");
				jsonUserTestValue.append("value");
				jsonUserTestValue.append("\":\"");
				jsonUserTestValue.append(supplierPo.getSupplierId());
				jsonUserTestValue.append("\",\"text\":\"");
				jsonUserTestValue.append(supplierPo.getCompanyName());
				jsonUserTestValue.append("\"},");
			}
			jsonUserTestValue = new StringBuffer(jsonUserTestValue.substring(0, jsonUserTestValue.length() - 1));
			jsonUserTestValue.append("]");
		}
		return jsonUserTestValue.toString();
	}

	public String getSupByMaterType(int materType) throws GenericException {
		List<SupplierPo> supplierList = supplierDao.getSupByMaterType(materType);
		StringBuffer jsonUserTestValue = new StringBuffer("");

		if (supplierList != null && supplierList.size() > 0) {

			jsonUserTestValue.append("[");
			for (SupplierPo supplierPo : supplierList) {
				jsonUserTestValue.append("{\"");
				jsonUserTestValue.append("value");
				jsonUserTestValue.append("\":\"");
				jsonUserTestValue.append(supplierPo.getSupplierId());
				jsonUserTestValue.append("\",\"text\":\"");
				jsonUserTestValue.append(supplierPo.getCompanyName());
				jsonUserTestValue.append("\"},");
			}
			jsonUserTestValue = new StringBuffer(jsonUserTestValue.substring(0, jsonUserTestValue.length() - 1));
			jsonUserTestValue.append("]");
		}
		return jsonUserTestValue.toString();
	}

	public String getAlgetSupByMaterTypelSup() throws GenericException {
		List<SupplierPo> supplierList = supplierDao.getAllSup();
		StringBuffer jsonUserTestValue = new StringBuffer("");

		if (supplierList != null && supplierList.size() > 0) {

			jsonUserTestValue.append("[");
			for (SupplierPo supplierPo : supplierList) {
				jsonUserTestValue.append("{\"");
				jsonUserTestValue.append("value");
				jsonUserTestValue.append("\":\"");
				jsonUserTestValue.append(supplierPo.getSupplierId());
				jsonUserTestValue.append("\",\"text\":\"");
				jsonUserTestValue.append(supplierPo.getCompanyName());
				jsonUserTestValue.append("\"},");
			}
			jsonUserTestValue = new StringBuffer(jsonUserTestValue.substring(0, jsonUserTestValue.length() - 1));
			jsonUserTestValue.append("]");
		}
		return jsonUserTestValue.toString();
	}

	public String getAllShopPoJsonString(int space) throws GenericException {
		List<ShopPo> tShopPoList = null;
		tShopPoList = shopDaoImpl.getAllShopPo();

		StringBuffer ql = new StringBuffer();
		ql.append("[");
		if (space == 1) {
			ql.append("{\"shopId\":\"0\",\"shopName\":\"无\"},");
		}
		String q2 = "";
		if (tShopPoList != null && tShopPoList.size() > 0) {
			for (ShopPo shopPo : tShopPoList) {
				ql.append("{\"shopId\":\"" + shopPo.getShopId() + "\",\"shopName\":\"" + "ID:" + shopPo.getShopId() + "--" + shopPo.getShopName()
						+ "\"},");
			}
			q2 = ql.substring(0, ql.length() - 1) + "]";
		}
		return q2;
	}

	public String getStoreCustUserPoJsonString(int space) throws GenericException {
		List<ShopPo> tShopPoList = null;
		tShopPoList = userDaoImpl.getStoreCustUserPoForCust();

		StringBuffer ql = new StringBuffer();
		ql.append("[");
		if (space == 1) {
			ql.append("{\"storeCustId\":\"0\",\"shopName\":\"无\"},");
		}
		String q2 = "";
		if (tShopPoList != null && tShopPoList.size() > 0) {
			for (ShopPo shopPo : tShopPoList) {
				ql.append("{\"storeCustId\":\"" + shopPo.getShopId() + "\",\"shopName\":\"" + "ID:" + shopPo.getShopId() + "--"
						+ shopPo.getShopName() + "\"},");
			}
			q2 = ql.substring(0, ql.length() - 1) + "]";
		}
		return q2;
	}

	public int getSupIdByUserId(long userId) throws GenericException {

		SupplierUserPo tSupplierUserPo = supplierDao.getSupUserPoByUserId(userId);
		return (int) tSupplierUserPo.getSupId();
	}

	public int getSupStoreHouseIdByUserId(long supId) throws GenericException {
		StorePo tStorePo = supplierDao.getSupStoreHouseIdByUserId(supId);
		return tStorePo.getStoreHouseId();
	}

	public String getSupNameByUserId(long userId) throws GenericException {

		SupplierPo supplierPo = supplierDao.getSupPoByUserId(userId);
		return supplierPo.getCompanyName();
	}

	public SupplierPo getSupPoByUserId(long userId) throws GenericException {
		return supplierDao.getSupPoByUserId(userId);
	}

	public List<SupplierUserPo> getSupplierUserPo(SupplierUserVo tSupplierUserVo) throws GenericException {
		return supplierDao.getSupplierUserPo(tSupplierUserVo);
	}

	public List<SupplierShopPo> getSupplierShopPo(SupplierShopVo c) throws GenericException {
		return supplierShopDao.getSupplierShopPo(c);

	}

	public SupplierVo getSupVoBySupId(String supId) throws GenericException {
		SupplierPo supplierPo = supplierDao.getSupPoBySupId(supId);
		SupplierVo supplierVo = new SupplierVo();
		BeanCopier copier = BeanCopier.create(SupplierPo.class, SupplierVo.class, false);
		copier.copy(supplierPo, supplierVo, null);
		return supplierVo;
	}

	public SupplierPo getSupPoBySupId(int supId) throws GenericException {
		return supplierDao.getSupPoBySupId(String.valueOf(supId));
	}

	public List<SupplierPo> getSupPoAll() throws GenericException {
		return supplierDao.getSupPoAll();

	}

	public SupplierQualificationPo getSupplierQualificationPoByQid(int qid) throws GenericException {
		return supplierDao.getSupplierQualificationPoByQid(qid);

	}

	public List<Object[]> getAllTotalByDate(String date, int supId, int custId, String custIdAll, String orderBy) throws GenericException {
		return supplierDao.getAllTotalByDate(date, supId, custId, custIdAll, orderBy);
	}

	public List<Object[]> getAllTotalByDate(String date, int supId, String custIdAll, String orderBy) throws GenericException {
		return supplierDao.getAllTotalByDate(date, supId, custIdAll, orderBy);
	}

	public List<Object[]> getAllTotalByDate(String date, int supId) throws GenericException {
		return supplierDao.getAllTotalByDate(date, supId);

	}

	public List<Object[]> getCustQuotationDate(int supId) throws GenericException {
		return supplierDao.getCustQuotationDate(supId);
	}

	public List<Object[]> getAllTotalByUserIdALl(String date, int supId, String userIdAll) throws GenericException {
		return supplierDao.getAllTotalByUserIdALl(date, supId, userIdAll);

	}

	public List<Object[]> getSupDistributeSummarySheet(String date, int supId, String materType, int storeHouseId, String shopIdAll)
			throws GenericException {
		return supplierDao.getSupDistributeSummarySheet(date, supId, materType, storeHouseId, shopIdAll);

	}

	public List<Object[]> getSupDistributeSummarySheetForGroupbyMaterType(String date, int supId) throws GenericException {
		return supplierDao.getSupDistributeSummarySheetForGroupbyMaterType(date, supId);

	}

	public List<Object[]> getSupDistributeSummarySheetForMaterOrder(String date, int supId, int materId, int storeHouseId, String shopIdAll)
			throws GenericException {
		return supplierDao.getSupDistributeSummarySheetForMaterOrder(date, supId, materId, storeHouseId, shopIdAll);
	}

	public List<Object> getSupDistributeSummarySheetLeaveMessageForMaterOrder(String date, int supId, int materId, String shopIdAll)
			throws GenericException {
		return supplierDao.getSupDistributeSummarySheetLeaveMessageForMaterOrder(date, supId, materId, shopIdAll);
	}

	public List<Object[]> getSupDistributLeaveMessage(String date, int supId) throws GenericException {
		return supplierDao.getSupDistributLeaveMessage(date, supId);
	}

	public List<Object[]> getExcelCust(String date, int supId) throws GenericException {
		return supplierDao.getExcelCust(date, supId);
	}

	public List<Object[]> getExcelCust(String date, int supId, String custIdAll) throws GenericException {
		return supplierDao.getExcelCust(date, supId, custIdAll);
	}

	public List<Object[]> getExcelCustForDistribute(String userIdAll) throws GenericException {
		return supplierDao.getExcelCustForDistribute(userIdAll);
	}

	public List<Object[]> getExcelCustAllRealMaterByDate(String date, int supId, String custId) throws GenericException {
		return supplierDao.getExcelCustAllRealMaterByDate(date, supId, custId);
	}

	public List<Object[]> getExcelCustAllRealMaterByDateForPrint(String date, int supId, String custId) throws GenericException {
		return supplierDao.getExcelCustAllRealMaterByDateForPrint(date, supId, custId);
	}

	public List<Object[]> getExcelCustAllRealMaterByDateForPrintCost(String date, int supId, String custId) throws GenericException {
		return supplierDao.getExcelCustAllRealMaterByDateForPrintCost(date, supId, custId);
	}

	public List<Object[]> getExcelCustTotalRealMaterByDateMaterIdMaterLevel(String date, int supId, String custId, String materId, String materLevel)
			throws GenericException {
		return supplierDao.getExcelCustTotalRealMaterByDateMaterIdMaterLevel(date, supId, custId, materId, materLevel);
	}

	@Override
	public boolean addSupplierCust(ShopSupplierVo c, Long[] suptypes) throws GenericException {
		// 校验
		List<ShopSupplierTypePo> shopSupplierTypePoList = supplierDao.getSuppCusPo(c);
		if (shopSupplierTypePoList != null && shopSupplierTypePoList.size() > 0) {
			msg = "msg0003";
			return false;
		}
		shopSupplierTypePoList = null;

		if (suptypes == null || suptypes.length == 0) {
			msg = "种类不能为空！";
			return false;
		}

		for (int i = 0; i < suptypes.length; i++) {
			// 校验 其他供货商是否有关系
			/*
			 * ShopSupplierVo checkVo = new ShopSupplierVo();
			 * checkVo.setShopId(c.getShopId());
			 * checkVo.setSupType(suptypes[i].intValue()); shopSupplierPoList =
			 * supplierDao.getSuppCusPoByTypeCheck(checkVo); if
			 * (shopSupplierPoList != null && shopSupplierPoList.size() > 0) {
			 * msg = "msg0003"; return false; } else { shopSupplierPoList =
			 * null; }
			 */
			// 插入
			ShopSupplierTypePo shopSupplierTypePo = new ShopSupplierTypePo();
			shopSupplierTypePo.setSupId(c.getSupId());
			shopSupplierTypePo.setSupType(suptypes[i].intValue());
			shopSupplierTypePo.setShopId(c.getShopId());
			supplierDao.addShopSupplierTypePo(shopSupplierTypePo);
		}
		// //创建供货商 客户关系表 能够让供货商管控商店
		// 查询是否存在
		SupplierShopVo supplierShopVo = new SupplierShopVo();
		supplierShopVo.setShopId(c.getShopId());
		supplierShopVo.setSupId(c.getSupId());
		List<SupplierShopPo> listSupplierShopPo = supplierShopDao.getSupplierShopPo(supplierShopVo);

		if (listSupplierShopPo == null || listSupplierShopPo.size() == 0) {
			SupplierShopPo tSupplierShop = new SupplierShopPo();
			tSupplierShop.setShopId(c.getShopId());
			tSupplierShop.setSupId(c.getSupId());
			tSupplierShop.setSupName(supplierDao.getSupPoBySupId(String.valueOf(c.getSupId())).getCompanyName());
			tSupplierShop.setCode("无");
			supplierShopDao.addSupplierShopDao(tSupplierShop);
		}
		return true;
	}

	@Override
	public boolean updateShopSupplier(ShopSupplierVo c, Long[] suptypes) throws GenericException {
		if (suptypes == null || suptypes.length == 0) {
			msg = "种类不能为空！";
			return false;
		}
		// 校验现在勾选的种类都是此供货商 或者没有

		List<ShopSupplierTypePo> shopSupplierTypePoList = null;

		/*
		 * for (int i = 0; i < suptypes.length; i++) { // 校验 其他供货商是否有关系
		 * ShopSupplierVo checkVo = new ShopSupplierVo();
		 * checkVo.setShopId(c.getShopId());
		 * checkVo.setSupType(suptypes[i].intValue()); shopSupplierTypePoList =
		 * supplierDao.getSuppCusPoByTypeCheck(checkVo); if
		 * (shopSupplierTypePoList != null && shopSupplierTypePoList.size() > 0)
		 * { if (shopSupplierTypePoList.get(0).getSupId() == c.getSupId()) {
		 * shopSupplierTypePoList = null; } else { msg = "msg0003"; return
		 * false; } } else { shopSupplierTypePoList = null; } }
		 */
		// 删除此用户的此供货商的关联关系
		supplierDao.deleteShopSupplierTypePo(c.getShopId(), c.getSupId());
		for (int i = 0; i < suptypes.length; i++) {
			// 插入
			ShopSupplierTypePo shopSupplierTypePo = new ShopSupplierTypePo();
			shopSupplierTypePo.setSupId(c.getSupId());
			shopSupplierTypePo.setSupType(suptypes[i].intValue());
			shopSupplierTypePo.setShopId(c.getShopId());
			supplierDao.addShopSupplierTypePo(shopSupplierTypePo);
		}
		// //创建供货商 客户关系表 能够让供货商管控商店
		// 查询是否存在
		SupplierShopVo supplierShopVo = new SupplierShopVo();
		supplierShopVo.setShopId(c.getShopId());
		supplierShopVo.setSupId(c.getSupId());
		List<SupplierShopPo> listSupplierShopPo = supplierShopDao.getSupplierShopPo(supplierShopVo);

		if (listSupplierShopPo == null || listSupplierShopPo.size() == 0) {
			SupplierShopPo tSupplierShop = new SupplierShopPo();
			tSupplierShop.setShopId(c.getShopId());
			tSupplierShop.setSupId(c.getSupId());
			tSupplierShop.setSupName(supplierDao.getSupPoBySupId(String.valueOf(c.getSupId())).getCompanyName());
			tSupplierShop.setCode("无");
			supplierShopDao.addSupplierShopDao(tSupplierShop);
		}
		return true;
	}

	public void deleteShopSupplier(int shopId, int supId) throws GenericException {

		supplierDao.deleteShopSupplierTypePo(shopId, supId);

	}

	public String updateSupplier(SupplierVo c) throws GenericException {
		SupplierPo po = new SupplierPo();
		BeanCopier copier1 = BeanCopier.create(SupplierVo.class, SupplierPo.class, false);
		copier1.copy(c, po, null);
		po.setUpdatetime(PubFun.getCurrentDate());
		supplierDao.updateSupplier(po);
		userService.updateRoleByUserId(String.valueOf(po.getUserId()), c.getRoles());
		return "0000";
	}

	@Override
	public List<MaterLevelPo> getMaterLevelPoByMaterIdSupId(int materId, int supId) throws GenericException {

		return supplierDao.getMaterLevelPoByMaterIdSupId(materId, supId);
	}

	public List<Code> listAllSuptype() throws GenericException {
		return supplierDao.findCodes();
	}

	public List<CodeVo> listAllSuptypeByUpdate(int shopId, int supId) throws GenericException {
		List<Code> poList = supplierDao.findCodes();

		ShopSupplierVo v = new ShopSupplierVo();
		v.setSupId(supId);
		v.setShopId(shopId);
		List<ShopSupplierTypePo> shopSupplierTypePoList = supplierDao.getSuppCusPo(v);

		List<CodeVo> checkedRoleList = new ArrayList<CodeVo>(); // 分配给该用户的角色
		List<CodeVo> uncheckedRoleList = new ArrayList<CodeVo>(); // 没有分配给该用户的角色
		try {
			if (poList != null && poList.size() > 1) {
				for (Code po : poList) {
					CodeVo vo = new CodeVo();
					BeanUtils.copyProperties(vo, po);
					int i = 0;
					for (i = 0; i < shopSupplierTypePoList.size(); i++) {
						ShopSupplierTypePo shopSupplierTypePo = shopSupplierTypePoList.get(i);
						if (vo.getCodeOder() == shopSupplierTypePo.getSupType()) {
							vo.setChecked("true");
							break;
						}
					}
					if (i == shopSupplierTypePoList.size()) {
						uncheckedRoleList.add(vo);
					} else {
						checkedRoleList.add(vo);
					}
				}
			}
			checkedRoleList.addAll(uncheckedRoleList);
		} catch (Exception e) {
			throw new RuntimeException("查询失败!");
		}

		return checkedRoleList;
	}

	public boolean importSupMaterValue(Map<Integer, String> map, String custIdAll) throws Exception {
		// 校验
		String materDayForUserIdCheck = "";
		int supId = 0;
		String materDay = "";
		for (int i = 1; i <= map.size(); i++) {
			// 长度校验
			String[] everyline = map.get(i).split("\\*");
			String materDayCheck = everyline[4];
			materDayForUserIdCheck = materDayCheck;
			String materValueUndressedCheck = everyline[5];
			supId = Integer.valueOf(everyline[2]);
			materDay = everyline[4];
			// BigDecimal materValueUndressed = new BigDecimal(everyline[7]);

			// 时间格式校验
			String eL = "[0-9]{4}-[0-9]{2}-[0-9]{2}";
			Pattern p = Pattern.compile(eL);
			Matcher m = p.matcher(materDayCheck);
			boolean dateFlag = m.matches();
			if (!dateFlag) {
				msg = "msg003";
				return false;
			}
			// 验证价格
			String eLvalue = "^[0-9]+(.[0-9]{0,2})?$";
			p = Pattern.compile(eLvalue);
			m = p.matcher(materValueUndressedCheck);
			boolean valueFlag = m.matches();
			if (!valueFlag) {
				msg = "msg004";
				return false;
			}

		}

		String[] userIdArray = custIdAll.split(",");
		// 对用户的校验 提高效率
		List<String> userIdListForlist = Arrays.asList(userIdArray);
		List<String> userIdList = new ArrayList<String>();
		for (String userId : userIdListForlist) {
			List<ShopPo> userPoList = userDaoImpl.getUserPoByOrderDateAndUserId(materDayForUserIdCheck, userId);
			if (userPoList != null && userPoList.size() > 0) {
				userIdList.add(userId);
			}
		}

		ExecutorService exe = Executors.newFixedThreadPool(50);
		for (int i = 1; i <= map.size(); i++) {
			exe.execute(new ExcelInMaterValue(i, map, userIdList, supplierOrderDao, materDaoImpl, selectFoodDaoImpl));
		}
		exe.shutdown();
		while (true) {
			if (exe.isTerminated()) {
				System.out.println("结束了！");
				break;
			}
			Thread.sleep(1);
		}
		// 修改总表的总价
		// 查询真实总价格 ---下
		List<OrderSupplierPo> orderSupplierPoList = selectFoodDaoImpl.getOrderSupplierPoByOrdDateAndSupIdAndCustIdAll(materDay, supId, custIdAll);
		if (orderSupplierPoList != null && orderSupplierPoList.size() > 0) {
			for (OrderSupplierPo orderSupplierPo : orderSupplierPoList) {
				BigDecimal valueReal = supplierOrderDao.computeValueReal(orderSupplierPo.getOrdId(), orderSupplierPo.getOrdSupId());
				// 查询真实总价格 ---上
				orderSupplierPo.setOrdValueReal(valueReal);
				selectFoodDaoImpl.updateOrderSupplier(orderSupplierPo);
			}
		}
		return true;
	}

	public boolean importSupMaterValueForWeb(MaterVo materVo) throws Exception {
		JSONArray array = JSONArray.fromObject(materVo.getMaterJson());

		List<MaterVo> materVoList = new ArrayList<MaterVo>();
		for (int i = 0; i < array.size(); i++) {
			JSONObject object = JSONObject.fromObject(array.get(i));
			MaterVo tMaterVo = new MaterVo();
			tMaterVo.setMaterId(Integer.valueOf(object.get("materId").toString()));
			tMaterVo.setMaterLevel(Integer.valueOf(object.get("materLevel").toString()));
			tMaterVo.setMaterValue(new BigDecimal(object.get("materValue").toString()));
			tMaterVo.setMaterValueUndressed(new BigDecimal(object.get("materValueUndressed").toString()));
			tMaterVo.setMaterWeight(object.get("materWeight").toString());
			tMaterVo.setDate(object.get("date").toString());
			tMaterVo.setSupId(materVo.getSupId());
			tMaterVo.setCustId(materVo.getCustId());
			tMaterVo.setOrdId(materVo.getOrdId());
			materVoList.add(tMaterVo);
		}

		ExecutorService exe = Executors.newFixedThreadPool(50);
		for (int i = 0; i <= materVoList.size() - 1; i++) {
			exe.execute(new ExcelInMaterValueForWeb(i, materVoList, supplierOrderDao, materDaoImpl, selectFoodDaoImpl));
		}
		exe.shutdown();
		while (true) {
			if (exe.isTerminated()) {
				System.out.println("结束了！");
				break;
			}
			Thread.sleep(1);
		}
		// 修改总表的总价
		// 查询真实总价格 ---下
		List<OrderSupplierPo> orderSupplierPoList = selectFoodDaoImpl.getOrderSupplierPoByOrdDateAndSupIdAndCustIdAll(materVo.getDate(),
				materVo.getSupId(), String.valueOf(materVo.getCustId()));
		if (orderSupplierPoList != null && orderSupplierPoList.size() > 0) {
			for (OrderSupplierPo orderSupplierPo : orderSupplierPoList) {
				BigDecimal valueReal = supplierOrderDao.computeValueReal(orderSupplierPo.getOrdId(), orderSupplierPo.getOrdSupId());
				// 查询真实总价格 ---上
				orderSupplierPo.setOrdValueReal(valueReal);
				selectFoodDaoImpl.updateOrderSupplier(orderSupplierPo);
			}
		}
		return true;
	}

	public boolean importSupMaterValueCost(Map<Integer, String> map) throws Exception {
		// 校验
		String materDayForUserIdCheck = "";
		int supId = 0;
		for (int i = 1; i <= map.size(); i++) {
			// 长度校验
			String[] everyline = map.get(i).split("\\*");
			String materDayCheck = everyline[4];
			materDayForUserIdCheck = materDayCheck;
			String materValueUndressedCheck = everyline[5];
			supId = Integer.valueOf(new BigDecimal(everyline[2]).intValue());
			// BigDecimal materValueUndressed = new BigDecimal(everyline[7]);

			// 时间格式校验
			String eL = "[0-9]{4}-[0-9]{2}-[0-9]{2}";
			Pattern p = Pattern.compile(eL);
			Matcher m = p.matcher(materDayCheck);
			boolean dateFlag = m.matches();
			if (!dateFlag) {
				msg = "msg003";
				return false;
			}
			// 验证价格
			String eLvalue = "^[0-9]+(.[0-9]{0,2})?$";
			p = Pattern.compile(eLvalue);
			m = p.matcher(materValueUndressedCheck);
			boolean valueFlag = m.matches();
			if (!valueFlag) {
				msg = "msg004";
				return false;
			}

		}

		// 取得订单日有订单的客户
		List<ShopPo> shopList = userDaoImpl.getUserPoByOrderDateAndSupId(materDayForUserIdCheck, supId);
		// 批处理
		ExecutorService exe = Executors.newFixedThreadPool(50);
		for (int i = 1; i <= map.size(); i++) {
			exe.execute(new ExcelInMaterValueCost(i, map, shopList, supplierOrderDao, materDaoImpl, selectFoodDaoImpl, materComputerServiceImpl));
		}
		exe.shutdown();
		while (true) {
			if (exe.isTerminated()) {
				System.out.println("结束了！");
				break;
			}
			Thread.sleep(1);
		}

		return true;
	}

	public boolean importSupMaterValueCostForWeb(MaterVo materVo) throws Exception {

		JSONArray array = JSONArray.fromObject(materVo.getMaterJson());

		/*
		 * List<MaterVo> materVoList = new ArrayList<MaterVo>(); for (int i = 0;
		 * i < array.size(); i++) { JSONObject object =
		 * JSONObject.fromObject(array.get(i)); MaterVo tMaterVo = new
		 * MaterVo();
		 * tMaterVo.setMaterId(Integer.valueOf(object.get("materId").toString
		 * ()));
		 * tMaterVo.setMaterLevel(Integer.valueOf(object.get("materLevel").
		 * toString())); tMaterVo.setMaterValue(new
		 * BigDecimal(object.get("materValue").toString()));
		 * tMaterVo.setDate(object.get("date").toString());
		 * tMaterVo.setSupId(materVo.getSupId()); materVoList.add(tMaterVo); }
		 */
		// 取得订单日有订单的客户
		if (materVo.getCostFlag() == 0) {
			List<ShopPo> shopList = userDaoImpl.getUserPoByOrderDateAndSupId(materVo.getDate(), materVo.getSupId());
			// 批处理
			ExecutorService exe = Executors.newFixedThreadPool(50);
			for (int i = 0; i <= array.size() - 1; i++) {
				exe.execute(new ExcelInMaterValueCostForWeb(JSONObject.fromObject(array.get(i)), shopList, supplierOrderDao, materDaoImpl,
						selectFoodDaoImpl, materComputerServiceImpl, materVo.getSupId()));
			}
			exe.shutdown();
			while (true) {
				if (exe.isTerminated()) {
					System.out.println("结束了！");
					break;
				}
				Thread.sleep(1);
			}
			return true;
		} else if (materVo.getCostFlag() == 1) {
			// 供货商临时加货
			List<ShopPo> shopList = new ArrayList<ShopPo>();
			ShopPo a = new ShopPo();
			a.setShopId(materVo.getCustId());
			shopList.add(a);
			// 批处理
			ExecutorService exe = Executors.newFixedThreadPool(50);
			for (int i = 0; i <= array.size() - 1; i++) {
				exe.execute(new ExcelInMaterValueCostForSup(JSONObject.fromObject(array.get(i)), shopList, supplierOrderDao, materDaoImpl,
						selectFoodDaoImpl, materComputerServiceImpl, materVo.getSupId()));
			}
			exe.shutdown();
			while (true) {
				if (exe.isTerminated()) {
					System.out.println("结束了！");
					break;
				}
				Thread.sleep(1);
			}
			return true;
		}
		return false;

	}

	public boolean importSupMaterValueCostForOnlyCost(MaterVo materVo) throws Exception {
		JSONArray array = JSONArray.fromObject(materVo.getMaterJson());

		for (int i = 0; i < array.size(); i++) {
			JSONObject object = JSONObject.fromObject(array.get(i));
			int materId = Integer.valueOf(object.get("materId").toString());
			// BigDecimal ordMaterWeight = new
			// BigDecimal(object.get("materWeight").toString());
			BigDecimal ordMaterValueRealUnit = new BigDecimal(object.get("materValue").toString());

			List<MaterLevelCblPo> materLevelCblPoList = materDaoImpl.getMaterLevelCblPoByMaterIdAndSupIdAndMaterDay(materId, materVo.getSupId(),
					materVo.getDate());
			if (materLevelCblPoList != null && materLevelCblPoList.size() > 0) {
				MaterLevelCblPo tMaterLevelCblPo = materLevelCblPoList.get(0);
				tMaterLevelCblPo.setMaterValue(ordMaterValueRealUnit.multiply(new BigDecimal(0.001)));
				tMaterLevelCblPo.setMaterValueUndressed(ordMaterValueRealUnit.multiply(new BigDecimal(0.001)));
				materDaoImpl.updateMaterLevelCbl(tMaterLevelCblPo);
			} else {
				MaterLevelCblPo tMaterLevelCblPo = new MaterLevelCblPo();
				tMaterLevelCblPo.setSupId(materVo.getSupId());
				tMaterLevelCblPo.setMaterDay(materVo.getDate());
				tMaterLevelCblPo.setMaterLevel(1);
				tMaterLevelCblPo.setMaterValue(ordMaterValueRealUnit.multiply(new BigDecimal(0.001)));
				tMaterLevelCblPo.setMaterValueUndressed(ordMaterValueRealUnit.multiply(new BigDecimal(0.001)));
				materDaoImpl.addMaterLevelCbl(tMaterLevelCblPo);
			}

		}
		return true;
	}

	public void computeTotalValue(String materDay, int supId, int ordId) throws Exception {
		// 改总表的进货出货总价
		// 查询真实总价格 ---下
		List<OrderSupplierPo> orderSupplierPoList = selectFoodDaoImpl.getOrderSupplierPoByOrdDateAndSupId(materDay, supId);
		if (orderSupplierPoList != null && orderSupplierPoList.size() > 0) {
			for (OrderSupplierPo orderSupplierPo : orderSupplierPoList) {

				BigDecimal valueRealCost = supplierOrderDao.computeValueRealCost(orderSupplierPo.getOrdId(), orderSupplierPo.getOrdSupId());
				// 查询真实总价格 ---上
				orderSupplierPo.setOrdValueRealCost(valueRealCost.toString());

				BigDecimal valueReal = supplierOrderDao.computeValueReal(orderSupplierPo.getOrdId(), orderSupplierPo.getOrdSupId());
				// 查询真实总价格 ---上
				orderSupplierPo.setOrdValueReal(valueReal);
				orderSupplierPo.setOrdImportValue(1);

				if (ordId == 0 || ordId == orderSupplierPo.getOrdId()) {
					selectFoodDaoImpl.updateOrderSupplier(orderSupplierPo);
				} else {
					continue;
				}
			}
		}
	}

	public List<Object[]> getUserIdDistributePoList(String ordDate, int supId) throws GenericException {
		return supplierDao.getUserIdDistributePoList(ordDate, supId);
	}

	public boolean checkSupplierQualificationName(SupplierQualificationVo supplierQualificationVo) throws GenericException {
		// 检查同名
		List<SupplierQualificationPo> list = selectFoodDaoImpl.getSupplierQualificationPoListByName(supplierQualificationVo.getName());
		if (list != null && list.size() > 0) {
			this.msg = "msg001";
			return true;
		}
		return false;
	}

	public void addSupplierQualificationPo(SupplierQualificationVo supplierQualificationVo) throws GenericException {
		SupplierQualificationPo supplierQualificationPo = new SupplierQualificationPo();
		BeanCopier copier = BeanCopier.create(SupplierQualificationVo.class, SupplierQualificationPo.class, false);
		copier.copy(supplierQualificationVo, supplierQualificationPo, null);
		supplierDao.addSupplierQualificationPo(supplierQualificationPo);
	}

	public boolean deleteSupplierQualification(int qid) throws GenericException {

		String link = "/home/supplierQualification/" + supplierDao.getSupplierQualificationPoByQid(qid).getName();
		DeleteFileUtil.deleteFile(link);
		supplierDao.deleteSupplierQualification(qid);
		return true;
	}

	public boolean importSupMaterRealityWeight(List<Map<Integer, String>> list, String materDay, int supId) throws Exception {

		for (Map<Integer, String> map : list) {
			for (int i = 1; i <= map.size(); i++) {
				// 长度校验
				String[] everyline = map.get(i).split("\\*");
				long shopId = Long.valueOf(everyline[0]);
				int materId = Integer.valueOf(everyline[2]);

				if (everyline.length < 9) {
					continue;
				}
				BigDecimal ordMaterWeight = new BigDecimal(everyline[8]);

				List<OrderSupplierMaterRealPo> orderSupplierMaterRealPoList = selectFoodDaoImpl.getOrderSupplierMaterRealPoBysupIdMaterDayMaterId(
						materDay, supId, shopId, materId);
				if (orderSupplierMaterRealPoList != null && orderSupplierMaterRealPoList.size() > 0) {
					// MathContext mc = new MathContext(5,
					// RoundingMode.HALF_UP);
					OrderSupplierMaterRealPo orderSupplierMaterRealPo = orderSupplierMaterRealPoList.get(0);
					orderSupplierMaterRealPo.setOrdMaterWeight(ordMaterWeight);
					orderSupplierMaterRealPo.setOrdMaterValue(orderSupplierMaterRealPo.getOrdMaterValueUnit().multiply(ordMaterWeight));
					orderSupplierMaterRealPo.setOrdMaterValueCost((new BigDecimal(orderSupplierMaterRealPo.getOrdMaterValueCostUnit())
							.multiply(ordMaterWeight)).toString());
					selectFoodDaoImpl.updateOrderSupplierMaterReal(orderSupplierMaterRealPo);
				}

			}

		}
		return true;
	}

	public boolean importSupMaterRealityWeightForWeb(MaterVo materVo) throws Exception {
		long shopId = materVo.getCustId();
		int supId = materVo.getSupId();
		String materDay = materVo.getDate();
		JSONArray array = JSONArray.fromObject(materVo.getMaterJson());

		for (int i = 0; i < array.size(); i++) {
			JSONObject object = JSONObject.fromObject(array.get(i));
			int materId = Integer.valueOf(object.get("materId").toString());
			BigDecimal ordMaterWeight = new BigDecimal(object.get("materWeight").toString());
			BigDecimal ordMaterValueRealUnit = new BigDecimal(object.get("materValue").toString());
			BigDecimal materValueCostUnit = new BigDecimal(object.get("materValueUndressed").toString());

			List<OrderSupplierMaterRealPo> orderSupplierMaterRealPoList = selectFoodDaoImpl.getOrderSupplierMaterRealPoBysupIdMaterDayMaterId(
					materDay, supId, shopId, materId);
			if (orderSupplierMaterRealPoList != null && orderSupplierMaterRealPoList.size() > 0) {
				OrderSupplierMaterRealPo orderSupplierMaterRealPo = orderSupplierMaterRealPoList.get(0);
				orderSupplierMaterRealPo.setOrdMaterWeight(ordMaterWeight);
				orderSupplierMaterRealPo.setOrdMaterValueUnit(ordMaterValueRealUnit);
				orderSupplierMaterRealPo.setOrdMaterValue(ordMaterValueRealUnit.multiply(ordMaterWeight));

				BigDecimal CostUnit = new BigDecimal(0);
				orderSupplierMaterRealPo.setOrdMaterValueCostUnit(materValueCostUnit.toString());
				if (orderSupplierMaterRealPo.getOrdMaterValueCostUnit() != null) {
					CostUnit = new BigDecimal(orderSupplierMaterRealPo.getOrdMaterValueCostUnit());
				}
				orderSupplierMaterRealPo.setOrdMaterValueCostUnit(CostUnit.toString());
				orderSupplierMaterRealPo.setOrdMaterValueCost((CostUnit.multiply(ordMaterWeight)).toString());
				selectFoodDaoImpl.updateOrderSupplierMaterReal(orderSupplierMaterRealPo);
			}

		}

		return true;
	}

	public boolean importSupMaterWeightForWeb(MaterVo materVo) throws Exception {
		long shopId = materVo.getCustId();
		int supId = materVo.getSupId();
		String materDay = materVo.getDate();
		JSONArray array = JSONArray.fromObject(materVo.getMaterJson());

		for (int i = 0; i < array.size(); i++) {
			JSONObject object = JSONObject.fromObject(array.get(i));
			int materId = Integer.valueOf(object.get("materId").toString());
			int ordId = Integer.valueOf(object.get("ordId").toString());
			BigDecimal ordMaterWeight = new BigDecimal(object.get("materWeight").toString());

			List<OrderSupplierMaterPo> orderSupplierMaterRealPoList = selectFoodDaoImpl.getOrderSupplierMaterPoByMateridOrdIdSupIdShopId(materId,
					ordId, supId, shopId);

			if (orderSupplierMaterRealPoList != null && orderSupplierMaterRealPoList.size() > 0) {
				OrderSupplierMaterPo orderSupplierMaterPo = orderSupplierMaterRealPoList.get(0);
				orderSupplierMaterPo.setOrdMaterWeight(ordMaterWeight);
				selectFoodDaoImpl.updateOrderSupplierMater(orderSupplierMaterPo);
			}

		}

		return true;
	}

	public boolean updateSupMaterWeightForBatch(MaterVo materVo) throws Exception {
		// 校验订单状态
		JSONArray array = JSONArray.fromObject(materVo.getMaterJson());
		for (int i = 0; i < array.size(); i++) {
			JSONObject object = JSONObject.fromObject(array.get(i));
			// int materId = Integer.valueOf(object.get("materId").toString());
			// BigDecimal ordMaterWeight = new
			// BigDecimal(object.get("materWeight").toString());
			String ordId = object.get("ordId").toString();
			String ordCustId = object.get("ordCustId").toString();
			OrderSupplierPo tOrderSupplierPo = supplierOrderDao.getOrderSup(ordId, ordCustId, String.valueOf(materVo.getSupId()));
			if (tOrderSupplierPo.getOrdState() != CommonType.ORD_SUP_WAIT) {
				msg = ordId + "号订单状态不对！";
				return false;
			}
		}

		for (int i = 0; i < array.size(); i++) {
			JSONObject object = JSONObject.fromObject(array.get(i));
			int materId = Integer.valueOf(object.get("materId").toString());
			BigDecimal ordMaterWeight = new BigDecimal(object.get("materWeight").toString());
			int ordId = Integer.valueOf(object.get("ordId").toString());
			// String ordCustId = object.get("ordCustId").toString();
			OrderSupplierMaterRealPo tOrderSupplierMaterRealPo = supplierOrderDao.getOrderSupMaterRealByOrdIdMaterIdSupId(ordId, materId,
					materVo.getSupId());
			tOrderSupplierMaterRealPo.setOrdMaterWeight(ordMaterWeight);
			selectFoodDaoImpl.updateOrderSupplierMaterReal(tOrderSupplierMaterRealPo);
		}

		return true;
	}

	public BigDecimal getMaterValueCostByMaterId(int materId, int supId) throws GenericException {

		List<Object[]> materValueCost = supplierDao.getMaterValueCostByMaterId(materId, supId);
		if (materValueCost != null && materValueCost.size() > 0) {
			Object value = materValueCost.get(0);
			BigDecimal a = new BigDecimal(value.toString());
			return a.setScale(2, BigDecimal.ROUND_HALF_UP);
		} else {
			return new BigDecimal(0);
		}
	}

	public BigDecimal getMaterValueRealByMaterId(int materId, BigDecimal materValueCost, int supId, long shopId) throws GenericException {
		return materComputerServiceImpl.ComputeMaterRaise(materValueCost, materId, supId, shopId);
	}

	public BigDecimal getMaterValueRealLastByMaterId(int materId, int supId, long shopId) throws GenericException {
		return materComputerServiceImpl.getMaterValueRealLastByMaterId(materId, supId, shopId);

	}

	public BigDecimal getMaterValueRealByMaterIdForLook(int materId, int supId, long shopId) throws GenericException {
		BigDecimal materValueCost = getMaterValueCostByMaterId(materId, supId);
		return materComputerServiceImpl.ComputeMaterRaise(materValueCost, materId, supId, shopId);
	}

	public ShopSupplierTypePo getShopSupplierTypePo(ShopSupplierTypeVo vo) throws GenericException {
		List<ShopSupplierTypePo> list = supplierDao.getShopSupplierTypePo(vo);
		if (list != null && list.size() > 0) {
			return list.get(0);
		} else {
			return null;
		}
	}

}
